import request from '@/utils/request'
import { baseResponse } from '@/types/public'
import {
  Course,
  AddCourse,
  AddCourseAttendance,
  CourseAttendanceStatisticalDate,
  StudentAttendance,
} from '@/types/teacher'

export const getCourseList = async () => {
  return (await request.get<baseResponse<Array<Course>>>('Teacher/GetTeacherCourses')).data
}

export const addCourse = async (courseName: string, className: string) => {
  return (
    await request.post<baseResponse<boolean>>(
      'Teacher/AddCourse',
      new AddCourse(courseName, className),
    )
  ).data
}

export const addCourseAttendance = async (layerId: number, courseName: string) => {
  return (
    await request.post<baseResponse<number>>(
      'Teacher/AddAttendanceRecord',
      new AddCourseAttendance(layerId, courseName),
    )
  ).data
}

export const getCourseAttendance = async () => {
  return (
    await request.get<baseResponse<CourseAttendanceStatisticalDate>>(
      'Teacher/GetAttendanceStatisticalList',
    )
  ).data
}

export const getStudentAttendance = async (attendanceID: number) => {
  return (
    await request.get<baseResponse<StudentAttendance>>(
      `Teacher/GetCourseAttendanceDate?attendanceId=${attendanceID}`,
    )
  ).data
}

export const DeleteCourse = async (courseName: string) => {
  return (
    await request.delete<baseResponse<boolean>>(`Teacher/DeleteCourse?courseName=${courseName}`)
  ).data
}
